package my.controller;

import com.jfinal.aop.Before;
import com.jfinal.core.Controller;
import my.common.Util;
import my.interceptor.Login;
import my.model.Category;
import my.service.CategoryService;

import java.util.List;

/**
 * Created by Administrator on 2017/6/8.
 */
public class CategoryController extends Controller {
    CategoryService categoryService = new CategoryService();

    @Before(Login.class)
    public void update() {
        Category category = getModel(Category.class, "", true);
        boolean success = categoryService.updateCategory(category);
        String message = success ? "日志分类更新成功" : "日志分类更新失败";
        renderJson(Util.ajaxJson(success, message));
    }


    public void json() {
        List<Category> categories = categoryService.getAllCategories();
        setAttr("data", categories);
        setAttr("success", true);
        renderJson();
    }
}
